package com.jsg.sl651.util;

import com.alibaba.fastjson2.JSONObject;
import com.jsg.sl651.entity.frame.header.MessageHeader;
import com.jsg.sl651.entity.station.AddressOfHydrologicalTelemetryStation;
import com.jsg.sl651.entity.station.OtherTelemetryStationAddresses;
import com.jsg.sl651.entity.station.RemoteTelemetryStationAddress;

public final class CopyUtil {
    //还是使用JSON 吧
    public static <T> T deepCopy(T source,Class<T> tClass) {
        return JSONObject.parseObject(JSONObject.toJSONString(source), tClass);
    }


    public static MessageHeader copyHeader(MessageHeader messageHeader) {
        MessageHeader copyData = deepCopy(messageHeader, MessageHeader.class);
        RemoteTelemetryStationAddress address = messageHeader.getRemoteTelemetryStationAddress();
        if (address instanceof AddressOfHydrologicalTelemetryStation) {
            AddressOfHydrologicalTelemetryStation addressOfHydrologicalTelemetryStation = deepCopy((AddressOfHydrologicalTelemetryStation) address, AddressOfHydrologicalTelemetryStation.class);
            copyData.setRemoteTelemetryStationAddress(addressOfHydrologicalTelemetryStation);
        }
        if (address instanceof OtherTelemetryStationAddresses) {
            OtherTelemetryStationAddresses otherTelemetryStationAddresses = deepCopy((OtherTelemetryStationAddresses) address, OtherTelemetryStationAddresses.class);
            copyData.setRemoteTelemetryStationAddress(otherTelemetryStationAddresses);
        }
        return copyData;
    }
}
